import React, { useState } from 'react';
import { Table, Select, DatePicker, Button, Row, Col } from 'antd';
import moment from 'moment';
import AutoTable from '@/components/AutoTable';
import { useRequest } from 'ahooks';
import { getFetch } from '@/utils/doFetch';
import useCurrentUser from '@/utils/useCurrentUser';
import dayjs from 'dayjs';


const ProjectLogs = () => {
  const { initialState: { range }, setInitialState } = useCurrentUser();

  const { data } = useRequest(async () => {
    let res = await getFetch({ url: "/user" });
    const users = res?.data?.dataList?.map(it => ({
      label: it.name,
      value: it.id
    })) ?? [];
    let res1 = await getFetch({ url: "/project" });
    const projects = res1?.data?.dataList?.map(it => ({
      label: it.projectName,
      value: it.id
    })) ?? [];
    return {
      users, projects
    }
  })


  const columns = [
    {
      title: '创建时间',
      dataIndex: 'createTime',
      key: 'createTime',
      search: false,
      width: "180px"
    },
    {
      title: '用户',
      dataIndex: 'userName',
      key: 'userId',
      valueType: "select",
      options: data?.users ?? [],
      width: "100px"
    },
    {
      title: '项目',
      dataIndex: 'projectName',
      key: 'projectId',
      valueType: "select",
      options: data?.projects ?? [],
      width: "180px"
    },
    {
      title: '任务节点',
      dataIndex: 'itemName',
      key: 'itemName',
      width: "180px"
    },
    {
      title: '是否删除',
      dataIndex: 'isDelete',
      key: 'isDelete',
      render: (text, record) => (record?.isDelete === 1 ? '是' : '否'), // 可选：将 0 和 1 转换为 "是" 或 "否"
      search: false,
      width: "120px"
    },
    {
      title: '信息',
      dataIndex: 'info',
      key: 'info',
      search: false,

    },
  ];

  return (
    <div className="project-logs">
      <AutoTable
        headerTitle="项目日志"
        path={"/project/getProjectLogPage"}
        columns={columns}
        method="post"
        actions={<div>日志列表</div>}
        extraparams={{
          startTm: range[0] ? dayjs(range[0]).format("YYYY-MM-DD") : null,
          endTm: range[1] ? dayjs(range[1]).format("YYYY-MM-DD") : null
        }}
      />
    </div>
  );
};

export default ProjectLogs;
